<?php
/**
 * Created by PhpStorm.
 * User: jungshen
 * Date: 2019/4/28
 * Time: 15:18
 */

namespace app\api\controller\other;


use app\api\controller\BasicApi;
use think\Db;

class Article extends BasicApi
{
    /**
     * 文章列表
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function index(){
        //查询文章列表
        $page_now=input('get.page_now/d',1);
        $page_size=input('get.page_size/d',10);
        $article=Db::name('article')
            ->field('id,image,title,content')
            ->where('status',1)
            ->order('sort asc')
            ->page($page_now,$page_size)
            ->select();
        return json(['data'=>$article,'msg'=>'success']);
    }

    /**
     * 文章详情
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function view(){
        $id=input('get.id/d');
        $article=Db::name('article')
            ->where('status',1)
            ->where('id',$id)
            ->field('title,content')
            ->find();
        return json(['data'=>$article,'msg'=>'success']);
    }
}